{% extends 'usercenter-base.html' %}
{% block title %}我的作业- 慕学在线网{% endblock %}
{% load staticfiles %}
{% block custom_css %}
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">

<link rel="stylesheet" type="text/css" href="{% static '' %}css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="{% static '' %}css/muke/course/common-less.css">
{% load filter %}


{% endblock %}
{% block custom_bread %}
     <section>
        <div class="wp">
            <ul  class="crumbs">
                <li><a href="{% url 'index' %}">首页</a>></li>
                <li><a href="{% url 'users:info' %}">个人中心</a>></li>
                <li>我的作业</li>
            </ul>
        </div>
    </section>
{% endblock %}

{% block rigt_form %}
<div class="right">
            <div class="personal_des Releasecont">
                <div class="head">
                    <h1>我的作业</h1>
                </div>
            </div>
            <div class="personal_des permessage">
                <div class="messagelist">
                    {% for work in myhomework %}
                    <form id="import-file-form_{{ work.id }}" action="{% url 'users:my_homework' %}" method='post' enctype="multipart/form-data" autocomplete="off"   target='frameFile'>
               {% csrf_token %}
                    <div class="messages" class="messages" style="border-bottom: 1px solid #edf1f2;">
                        <div class="fr">
                            <div class="top"><span >{{ work.course }}</span>
                                <i style="font-size: 2px;color: #aaac9c">（发布时间：{{ work.add_time }}）</i>
                                <input type="text"  id="text_{{ work.id }}" readonly="readonly" >
                                <input type="hidden" name="work_id" value="{{ work.id }}_{{ myhomework.number }}">
                                 <input type="file" id="file_{{ work.id }}" name="file" style="display:none">



                                {% if  request.user.submit_homework|list_in:work.id %}
                                <button disabled  onclick='selectfile({{ work.id }})' style="position: absolute;right: 5%" type="button" class="btn btn-outline-secondary btn-sm">
                                   已完成
                                </button>
                                    {% else %}
                                      <button onclick='selectfile({{ work.id }})' style="position: absolute;right: 5%" type="button" class="btn btn-outline-secondary btn-sm">
                                   提交作业
                                </button>
                                {% endif %}
                            </div>
                            <p>
                                <span>
                                    <i class="aui-iconfont aui-icon-notice">&nbsp;&nbsp;{{ work.name }}</i>
                                    <a href="{{ work.work.url }}"
                                       target="_blank" download="" data-id="274"
                                       style="position: relative;left: 3%">下载</a>
                                     <i style="position: absolute;left: 43%">发布教师 &nbsp;    {{ work.course.teacher.name }}</i>
                                    <i style="position:absolute;color: red;right: 5%">截止：{{ work.end_time }}</i>
                                </span>
                            </p>
                        </div>
                    </div>
                        </form>
                {% endfor%}

                </div>
            </div>
            <div class="pageturn pagerright">
              <ul class="pagelist">
             {% if myhomework.has_previous  %}
                 <li class="long"><a href="?page={{myhomework.previous_page_number}}">上一页</a></li>
            {%endif%}

                {% for i in   myhomework.paginator.page_range %}
                 {%if i == myhomework.number  %}
                     <li class="active"><a href="?page={{ i }}">{{i }}</a></li>
                    {% else %}
                      <li><a href="?page={{ i }}" class="page">{{ i }}</a></li>
                    {% endif %}
                {% endfor %}
                {% if myhomework.has_next  %}
                 <li class="long"><a href="?page={{myhomework.next_page_number}}">下一页</a></li>
            {%endif%}
            </ul>
            </div>
        </div>
{% endblock %}
{% block custom_js %}


<script type="text/javascript">
function selectfile(id) {



        var file = document.getElementById("file_"+id);

        var text = document.getElementById("text_"+id);
            //alert("hahaha");
            file.click();
        file.onchange = type;
        function type()
        {
            text.value = file.value;
            if(text.value.length>0){
                $('#import-file-form_'+id).submit();
            }
        }

   //注意：可兼容IE浏览器，推荐
    {# var fileInput = $("file_"+id).get(0).files[0];#}
    {#    if(fileInput){#}
	{#	$('#import-file-form_'+id).submit();#}

    {#        alert("请选择上传文件！");#}
    {#    }#}

    {#if (text.value.length!=0){#}
    {#    $('#import-file-form_'+id).submit();#}



}
$(function () {



})


        </script>




{% endblock %}

